﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Caliburn.Micro;
using MdcService.Configuration;
using MdcService.Factory;
using MdcService.Service;
using MdcService.Structure;
using MdcService.Structure.Enum;

namespace MdcMain
{
    public class InsertViewModel:Screen
    {
        public string Name { get; set; } = "";
        public string Path { get; set; } = "";

        private ConfigurationService _service;
        private MachineDefinition _machine;

        public InsertViewModel(AddMachineType type,ConfigurationService service)
        {
            DisplayName = "插入配置模板";
            _service = service;
            switch (type)
            {
                case AddMachineType.Moxa:
                    _machine = MachineFactory.CreateMoxaMachineDefinition(Path, Name);
                    break;
                case AddMachineType.Sinumerik:
                    _machine = MachineFactory.CreateSinumerikMachineDefinition(Path, Name);
                    break;
                case AddMachineType.Simluate:
                    _machine = MachineFactory.CreateSimulateMachineDefinition(Name, Path);
                    break;
                case AddMachineType.Testing:
                    _machine = MachineFactory.CreateTestingMachineDefinition(Name, Path);
                    break;;
            }
        }

        public void Ok()
        {
            _service.SaveMachines(_machine);
            TryClose();
        }

        public void Cancel()
        {
            this.TryClose();
        }
    }
}
